﻿using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;

namespace RuntimeCompiler
{
    public static class EnumExtensions
    {
        public static string GetEnumDescription( this Enum value )
        {
            FieldInfo fi = value.GetType().GetField( value.ToString() );
            var attributes =
                ( (DescriptionAttribute[])fi.GetCustomAttributes( typeof( DescriptionAttribute ), false ) ).ToList();

            if( attributes.Count > 0 )
                return attributes[ 0 ].Description;

            return value.ToString();
        }
    }
}

